package pers.leo.couplepointjava.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;
import pers.leo.couplepointjava.core.consts.Constants;
import pers.leo.couplepointjava.core.response.Result;
import pers.leo.couplepointjava.core.response.ResultController;
import pers.leo.couplepointjava.entity.CpPoint;
import pers.leo.couplepointjava.mapper.CpPointMapper;

import javax.annotation.Resource;

/**
 * 分值控制器
 *
 * @author Leo
 * @since  2021/8/24
 */
@RestController
@RequestMapping(Constants.PREFIX_API + "point")
public class CpPointController extends ResultController {

    @Resource
    private CpPointMapper cpPointMapper;

    /**
     * 分值详情
     * @param cpPoint 分值实体类
     * @return Result
     */
    @GetMapping("info")
    public Result info(CpPoint cpPoint) {
        try {
            // set default userId
            if (cpPoint != null && cpPoint.getUserId() == null) cpPoint.setUserId(Constants.DEFAULT_USER_ID);
//            if (cpPoint == null || cpPoint.getUserId() == null) throw new NullPointerException("用户编号不能为空！");

            CpPoint result = cpPointMapper.selectOne(new QueryWrapper<>(cpPoint));

            if (result == null) throw new NullPointerException("未知用户");

            return success(result);
        } catch (Exception e) {
            return failure(e.getMessage());
        }
    }

}
